package com.gold.config.environment;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Environment {

    private String name;
    private String[] profiles = new String[0];
    private String label;
    private List<PropertySource> propertySources = new ArrayList();
    private String version;
    private String state;

    public Environment(String name, String... profiles)
    {
        this(name, profiles, "master", null, null);
    }

    public Environment(Environment env)
    {
        this(env.getName(), env.getProfiles(), env.getLabel(), env.getVersion(), env.getState());
    }

    @JsonCreator
    public Environment(@JsonProperty("name") String name, @JsonProperty("profiles") String[] profiles, @JsonProperty("label") String label, @JsonProperty("version") String version, @JsonProperty("state") String state)
    {
        this.name = name;
        this.profiles = profiles;
        this.label = label;
        this.version = version;
        this.state = state;
    }

    public void add(PropertySource propertySource)
    {
        this.propertySources.add(propertySource);
    }

    public void addAll(List<PropertySource> propertySources)
    {
        this.propertySources.addAll(propertySources);
    }

    public void addFirst(PropertySource propertySource)
    {
        this.propertySources.add(0, propertySource);
    }

    public List<PropertySource> getPropertySources()
    {
        return this.propertySources;
    }

    public String getName()
    {
        return this.name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getLabel()
    {
        return this.label;
    }

    public void setLabel(String label)
    {
        this.label = label;
    }

    public String[] getProfiles()
    {
        return this.profiles;
    }

    public void setProfiles(String[] profiles)
    {
        this.profiles = profiles;
    }

    public String getVersion()
    {
        return this.version;
    }

    public void setVersion(String version)
    {
        this.version = version;
    }

    public String getState()
    {
        return this.state;
    }

    public void setState(String state)
    {
        this.state = state;
    }

    public String toString()
    {
        return "Environment [name=" + this.name + ", profiles=" + Arrays.asList(this.profiles) + ", label=" + this.label + ", propertySources=" + this.propertySources + ", version=" + this.version + ", state=" + this.state + "]";
    }

}
